﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;

namespace LI4.Data
{
    class Distrito
    {
        private Ligacao ligacao;

        public Distrito()
        {
            ligacao = new Ligacao();
        }

        public void Inserir(Candidato c)
        {
        }

        public void Alterar(Candidato c)
        {

        }
        public void Remover(Candidato c)
        {

        }

        public ArrayList getDistritos()
        {
            ArrayList array = new ArrayList();
            SqlDataReader reader;

            ligacao.Select("SELECT cod_distrito,nome FROM Distritos ORDER BY nome");
            reader = ligacao.mySqlDataReader;

            while(reader.Read())
                array.Add(new Business.Distrito(reader.GetInt32(0),reader.GetString(1)));

            reader.Close();
            return array;
        }

        public Business.Distrito getDistrito(int codigo)
        {
            SqlDataReader reader;

            ligacao.Select("SELECT nome FROM Distritos where cod_distrito='"+codigo+"'");
            reader = ligacao.mySqlDataReader;
            reader.Read();

            Business.Distrito distrito = new Business.Distrito(codigo, reader.GetString(0));

            return distrito;
        }
    }
}
